<?php
include_once('./common.php');
$moveid = empty($_GET['id'])?0:intval($_GET['id']);

//评论电影积分；
$query = $_SGLOBAL['db']->query("SELECT * FROM ".tname('app_moviecredit')." WHERE type='movie'");
$value = $_SGLOBAL['db']->fetch_array($query);
$_SGLOBAL[pingcredit] = $value['pingmovie'];
//评分
if (empty($_SGLOBAL[supe_uid])) {
	echo 'nouid';exit();
}
if ($_GET['fen']&&$moveid) {
	$fen = $_GET['fen'];
	//echo $fen.$moveid;exit();
	//判断是否存在；
	$query = $_SGLOBAL['db']->query("SELECT * FROM ".tname('app_movie_score')." WHERE uid='$_SGLOBAL[supe_uid]' AND movieid='$moveid'");
	if ($_SGLOBAL['db']->result($query)) {
		echo 'you';exit();
	}
	$data = array(
		'movieid' => $moveid,
		'uid' => $_SGLOBAL[supe_uid],
		'username' => $_SGLOBAL[supe_username],
		'dataline' => time(),
		'score' => $fen
	);
	inserttable('app_movie_score',$data);
	$_SGLOBAL['db']->query("UPDATE ".tname('app_movie')." SET score=score+$fen,scorenum=scorenum+1 WHERE  movieid='$moveid'");
	$_SGLOBAL['db']->query("UPDATE ".tname('space')." SET credit=credit+$_SGLOBAL[pingcredit] WHERE uid='$_SGLOBAL[supe_uid]'");
	$query = $_SGLOBAL['db']->query("SELECT score,scorenum FROM ".tname('app_movie')." WHERE movieid='$moveid'");
	$data = $_SGLOBAL['db']->fetch_array($query);
	$score = round($data[score]/$data[scorenum],1);
	//echo $data[score].'|'.$data[scorenum];exit();
	if ($score<2) {
		$score = '还未';
		$class = '';
	}if ($score==2) {
		$class = '1';
	}
	if ($score>2&&$score<=4) {
		$class = '2';
	}
	if ($score>4&&$score<=6) {
		$class = '3';
	}
	if ($score>6&&$score<=8) {
		$class = '4';
	}
	if ($score>8&&$score<=10) {
		$class = '5';
	}
	echo 'score'.$class.'|'.$score.'|'.$data[scorenum];
	exit();
}
if(!$_GET['fen']&&$moveid){
	$query = $_SGLOBAL['db']->query("SELECT * FROM ".tname('app_movie_keep')." WHERE uid='$_SGLOBAL[supe_uid]' AND movieid='$moveid'");
	if ($_SGLOBAL['db']->result($query)) {
		echo 'you';exit();
	}
	$data = array(
		'movieid' => $moveid,
		'uid' => $_SGLOBAL[supe_uid],
		'username' => $_SGLOBAL[supe_username],
		'dataline' => time(),
	);
	inserttable('app_movie_keep',$data);
	
	echo 'keep';
	exit();

}